from flask import jsonify

def success_response(data=None, message="Success", status_code=200):
    """
    返回成功请求的标准化响应
    :param data: 返回的数据
    :param message: 提示信息
    :param status_code: HTTP状态码
    :return: JSON响应
    """
    response = {
        "success": True,
        "message": message,
        "data": data
    }
    return jsonify(response), status_code

def error_response(message="Error", status_code=400, errors=None):
    """
    返回失败请求的标准化响应
    :param message: 错误信息
    :param status_code: HTTP状态码
    :param errors: 错误详情
    :return: JSON响应
    """
    response = {
        "success": False,
        "message": message,
        "errors": errors if errors else {}
    }
    return jsonify(response), status_code

def paginated_response(data, total, page, per_page, message="Success", status_code=200):
    """
    返回分页请求的标准化响应
    :param data: 当前页的数据
    :param total: 总数据量
    :param page: 当前页码
    :param per_page: 每页数据量
    :param message: 提示信息
    :param status_code: HTTP状态码
    :return: JSON响应
    """
    response = {
        "success": True,
        "message": message,
        "data": data,
        "pagination": {
            "total": total,
            "page": page,
            "per_page": per_page,
            "total_pages": (total + per_page - 1) // per_page
        }
    }
    return jsonify(response), status_code